package win.smartown.ada.remoteviews;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.NotificationCompat;
import android.view.View;
import android.widget.RemoteViews;

import win.smartown.ada.remoteviews.notification.NotificationReceiveActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void showSystemNotification(View view) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intent = new Intent(this, NotificationReceiveActivity.class);
        intent.putExtra("extra", "Click System Notification");
        Notification notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setTicker("ticker")
                .setContentTitle("content title")
                .setContentText("content text")
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
                .build();
        notificationManager.notify(1, notification);
    }

    public void showCustomNotification(View view) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.view_custom_notification);
        Intent intent1 = new Intent(this, NotificationReceiveActivity.class);
        intent1.putExtra("extra", "Click Custom Notification Button(id = action1)");
        remoteViews.setOnClickPendingIntent(R.id.action1, PendingIntent.getActivity(this, 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT));
        Intent intent2 = new Intent(this, NotificationReceiveActivity.class);
        intent2.putExtra("extra", "Click Custom Notification Button(id = action2)");
        remoteViews.setOnClickPendingIntent(R.id.action2, PendingIntent.getActivity(this, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT));
        Notification notification = new NotificationCompat.Builder(this)
                .setContent(remoteViews)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setTicker("ticker")
                .setContentTitle("content title")
                .setContentText("content text")
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .build();
        notificationManager.notify(2, notification);
    }
}
